package
{
	import UIFree.CLoader;
	
	import com.adobe.serialization.json.JSON;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	
	public class pj_checkTmpl extends Sprite {
		public static const BASEURL: String = 'http://vds-14a5.1gb.ru/';
		public static const TMPL_URL: String = BASEURL + 'pj/JPG/';
		public static const PREVIEW_URL: String = BASEURL + 'pj/jpg_preview/';
		
		private var _loader: Loader;
		private var lc: LoaderContext;
		public function pj_checkTmpl() {
			super();
			lc = new LoaderContext(false);
			
			var result: Array = pj_dataReset.resetData(pi_data.maskInfoList);
			result = result.sortOn('id');
			resetData(result, result, 17784);
		}
		
		protected function resetData(items: Array, result: Array, startID: int): void {
			items.forEach(function(item: Object, i: int, arr: Array): void {
				if (item.id >= startID)
					checkTmp(item, function(a_item: Object): void {
						trace(JSON.encode(a_item) + ',');
					})
			});	
		}
		
		protected function checkTmp(item: Object, doCompleteTmpl: Function): void {
			var count: int = 0;
			
			function doComplete(e: Event): void {
				count++;
				if (count >= 3) doCompleteTmpl(item);
			}
			
			new CLoader(null, TMPL_URL + item.id + '.jpg', doComplete, 0, 0, lc);
			new CLoader(null, TMPL_URL + item.id + 'm.jpg', doComplete, 0, 0, lc);
			new CLoader(null, PREVIEW_URL + 'i' + item.id + '.jpg', doComplete, 0, 0, lc);
		}
	}
}